﻿
Imports webctrl
Imports elpmis
Imports elpmis.internalFunctions

Namespace httpFunctions
    Public Class antiInputSpamCreator
        Inherits internalFunction

        Public Class parameters
            Public Const page As String = "page"
            Public Const query As String = "query"
        End Class

        Private Shared m As iParametersMapping = Nothing

        Shared Sub New()
            initialMapping(m, parameters.page, parameters.query)
        End Sub

        Protected Sub New(ByVal name As String)
            MyBase.new(name, m)
        End Sub

        Public Sub New()
            Me.New("antiInputSpam.create")
        End Sub

        Protected Function _invoke(ByVal ctx As context, ByRef output As antiInputSpam) As Boolean
            Dim page As xhtmlpage = Nothing
            ctx.findVariable(Of xhtmlpage)(parameters.page, page)
            Dim query As String = Nothing
            If ctx.findVariableStr(parameters.query, query) Then
                output = currentContext().createControl(New antiInputSpam(page, query, Nothing))
            Else
                output = currentContext().createControl(New antiInputSpam(page))
            End If
            Return True
        End Function

        Protected Overrides Function invoke(ByVal ctx As context, ByRef output As bare_variable) As Boolean
            Dim c As antiInputSpam = Nothing
            If _invoke(ctx, c) Then
                output = New bare_variable(typeDefination.var, c)
                Return True
            Else
                Return False
            End If
        End Function
    End Class

    Public Class antiInputSpamSetOnsubmitFunction
        Inherits internalFunction

        Public Class parameters
            Public Const page As String = "page"
            Public Const index As String = "index"
        End Class

        Private Shared m As iParametersMapping = Nothing

        Shared Sub New()
            initialMapping(m, parameters.page, parameters.index)
        End Sub

        Public Sub New()
            MyBase.New("antiInputSpam.setOnsubmitFunction", m)
        End Sub

        Protected Overrides Function invoke(ByVal ctx As context, ByRef output As bare_variable) As Boolean
            Dim page As xhtmlpage = Nothing
            ctx.findVariable(Of xhtmlpage)(parameters.page, page)
            Dim index As Int64 = Nothing
            If ctx.findVariableInt(parameters.index, index) Then
                output = New bare_variable(typeDefination.string, antiInputSpam.setOnsubmitFunction(page, index))
                Return True
            Else
                raiseError("expect parameter " + parameters.index, errorHandle.errorType.user)
                Return False
            End If
            Return True
        End Function
    End Class

    Public Class antiInputSpamAsTextCreator
        Inherits antiInputSpamCreator

        Public Sub New()
            MyBase.New("antiInputSpam.create.astext")
        End Sub

        Protected Overrides Function invoke(ByVal ctx As context, ByRef output As bare_variable) As Boolean
            Dim c As antiInputSpam = Nothing
            If _invoke(ctx, c) Then
                output = New bare_variable(typeDefination.string, Convert.ToString(c))
                Return True
            Else
                Return False
            End If
        End Function
    End Class

    Public Class antiInputSpamCheck
        Inherits internalFunction

        Public Class parameters
            Public Const query As String = "query"
        End Class

        Private Shared m As iParametersMapping = Nothing

        Shared Sub New()
            initialMapping(m, parameters.query)
        End Sub

        Public Sub New()
            MyBase.new("antiInputSpam.check", m)
        End Sub

        Protected Overrides Function invoke(ByVal ctx As context, ByRef output As bare_variable) As Boolean
            Dim query As String = Nothing
            Dim b As Boolean = False
            If ctx.findVariableStr(parameters.query, query) Then
                b = antiInputSpam.checkIpTable(query)
            Else
                b = antiInputSpam.checkIpTable()
            End If
            output = New bare_variable(typeDefination.bool, b)
            Return True
        End Function
    End Class
End Namespace
